package com.itheima.d2_polymorphism;

public class Test {
    public static void main(String[] args) {
        People p1 = new Student();
        p1.run();//编译看左边，运行看右边
        Student s2 =(Student)p1;
        s2.test();

        if(p1 instanceof Student){
            Student s3 =(Student) p1;
            s3.test();
        } else if(p1 instanceof Teacher){
            Teacher t2 =(Teacher) p1;
            t2.teach();
        }


        System.out.println("------------");

        People p2 = new Teacher();
        p2.run();//编译看左边，运行看右边

        Student s1 = new Student();
        go(s1);

        Teacher t1 = new Teacher();
        go(t1);
    }

    public static void go(People p1){
        if(p1 instanceof Student){
            Student s3 =(Student) p1;
            s3.test();
        } else if(p1 instanceof Teacher){
            Teacher t2 =(Teacher) p1;
            t2.teach();
        }
    }
}
